package com.tuanbiao.dialog;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.BasePopupView;
import com.lxj.xpopup.core.CenterPopupView;
import com.tuanbiao.R;

public class UploadErrorDialog extends CenterPopupView {

    private String errorMsg = "";
    private OnUploadMenuItemClickListener listener  = null;

    public UploadErrorDialog(@NonNull Context context) {
        super(context);
    }


    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_upload_error_layout;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        ((TextView)findViewById(R.id.dialogUploadText))
                .setText(errorMsg);
        findViewById(R.id.dialogUploadCancel)
                .setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        dismiss();
                    }
                });


        findViewById(R.id.dialogUploadRight)
                .setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        dismiss();
                        listener.onUploadClick(false);
                    }
                });
        findViewById(R.id.dialogUploadAll)
                .setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        dismiss();
                        listener.onUploadClick(true);
                    }
                });
    }

    public interface OnUploadMenuItemClickListener{
        void onUploadClick(boolean isAll);
    }

    public static void show(Context context,String msg,OnUploadMenuItemClickListener l){
        UploadErrorDialog pop = new UploadErrorDialog(context);
        pop.listener = l;
        pop.errorMsg = msg;
       new XPopup.Builder(context)
                .dismissOnTouchOutside(false)
                .dismissOnBackPressed(false)
                .asCustom(pop)
                .show();
    }
}
